<script>
	import {
		mapState
	} from 'vuex'
	import myWebsocket from "./common/myWebsocket.js"
	export default {
		computed: mapState(['isLogin', 'loginUserInfo']),
		onLaunch: function() {
			console.log('App Launch')
			// 属性初始化
			uni.getSystemInfo({
				success: function(e) {
					let height = e.windowHeight - uni.upx2px(155)
					Vue.prototype.swiperHeight = height
					console.log("可用高度为" + Vue.prototype.swiperHeight + "px")
					let width = e.windowWidth
					Vue.prototype.swiperWidth = width
					Vue.prototype.MAX_INTEGER = 2147483647
					console.log("可用宽度为" + Vue.prototype.swiperWidth + "px")
				}
			})
			// 开放接口
			// let urlPath = "http://172.25.229.167:8888/tangxz-chat"
			// let urlPath = "http://172.25.152.54:8888/tangxz-chat"
			let urlPath = "http://172.25.152.30:8888/tangxz-chat"
			let url = {
				tuser: {
					login: urlPath + "/tuser/login",
					getAllUser: urlPath + "/tuser/getAllUser",//{userId}
					save: urlPath + "/tuser/save",
					update: urlPath + "/tuser/update",
				},
				redis: {
					getOneUserInfo: urlPath + "/redis/getOneUserInfo/", //GET{userId}
					logout: urlPath + "/redis/logout", //POST
				}
			}
			Vue.prototype.url = url

			// 公共样式初始化
			let navbarBackground = {
				'background-image': 'linear-gradient(45deg, rgb(28, 187, 180), rgb(141, 198, 63))',
				'color': '#FFFFFF'
			}
			Vue.prototype.navbarBackground = navbarBackground
		},
		onShow: function() {
			console.log('App Show')
			//连接socket
			if (this.isLogin) {
				//形成登录消息
				var msg = myWebsocket.Msg("", this.$myEnum.type.TEXT, null);
				var msgContent = myWebsocket.MsgContent(this.$myEnum.action.CONNECT, this.loginUserInfo.id, "", msg,
					this.loginUserInfo)
				//连接 socket 并发送连接消息
				myWebsocket.connectSocket(msgContent)

				/**
				 * 打开数据库，如果这里没打开，则在登录页面，登录之后打开
				 */
				this.$mySqlite.openComDB(this.loginUserInfo.id, res => {
					console.log(res);
				})
			}
		},
		onHide: function() {
			console.log('App Hide')
		}
	}
</script>

<style>
	/*每个页面公共css */
	/* 引入colorui的内容 */
	@import "colorui/main.css";
	@import "colorui/icon.css";

	.status_bar {
		height: var(--status-bar-height);
		width: 100%;
	}

	.my-faj-center {
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.my-faj-space-between {
		display: flex;
		align-items: center;
		justify-content: space-between;
	}

	.my-text-1row {
		overflow: hidden;
		-webkit-line-clamp: 1;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-box-orient: vertical;
	}

	.my-text-2row {
		overflow: hidden;
		-webkit-line-clamp: 2;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-box-orient: vertical;
	}

	.my-text-3row {
		overflow: hidden;
		-webkit-line-clamp: 4;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-box-orient: vertical;
	}

	.my-text-4row {
		overflow: hidden;
		-webkit-line-clamp: 5;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-box-orient: vertical;
	}

	.my-text-5row {
		overflow: hidden;
		-webkit-line-clamp: 6;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-box-orient: vertical;
	}

	.text-indent {
		text-indent: 28px;
		font-size: 28rpx;
	}
</style>
